package com.leetone.orderservice.controller;

import com.leetone.orderservice.entity.Order;
import com.leetone.orderservice.mapper.OrderMapper;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderMapper orderMapper;

    @GetMapping("/findOrders/{userId}")
    @HystrixCommand(fallbackMethod = "findOrderfallback")//熔断器
    public List<Order> findOrder(@PathVariable("userid")Integer userid){
        List<Order> orders = orderMapper.selectOrder(userid);
        return orders;
    }
    
    /*
    * @description 【针对上面的熔断器发现的问题编写回调方法（参数要和返回值一样）】
     * @param null
    * @return 
    * @exception 
    * @author leetone 【leetone123@163.com】
    * @date 2019/4/27 10:08
    */
    public List<Order> findOrderfallback(Integer userid){
        List<Order> orders = new ArrayList<>();
        return orders;
    }
}
